package 代码记录.指定公司代码练习记录.西安.分值100分;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author zx
 * @create 2023-07-02 22:32
 * 看的题解：题解写的很棒
 */
public class 事件推送 {//7---copy---其实不难，看会了就没必要
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int R = sc.nextInt();
        int[] arrA = new int[m];
        int[] arrB = new int[n];
        for(int i = 0;i < m;i++){
            arrA[i] = sc.nextInt();
        }
        for(int i = 0;i < n;i++){
            arrB[i] = sc.nextInt();
        }
        int index = 0;
        List<int[]> list = new ArrayList<>();
        for(int i = 0;i < arrA.length;i++){
            int[] values = new int[2];
            while(index < arrB.length){
                if(arrB[index] >= arrA[i] && arrB[index] - arrA[i] <= R){
                    values[0] = arrA[i];
                    values[1] = arrB[index];
                    list.add(values);
                    break;//这个break很精妙，我自己肯定想不出来
                }
                index++;
            }
        }
        for(int[] i : list){
            System.out.println(i[0] + " " + i[1]);
        }
    }
}
